package com.example.projekt_anzeige;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class AnzeigenView extends View{

	private Paint paint;
	private Paint paint_2;
	private Paint paint_circle;
	private double position = 0;
	private double max =1;

	  public AnzeigenView(Context context) {
	    super(context);
	    init();
	    init_2();
	  }
	
	  public AnzeigenView(Context context, AttributeSet attrs){	 
		  super( context, attrs );
		   init();
		   init_2();
	  }
	  
	  public AnzeigenView(Context context, AttributeSet attrs, int defStyle){  
		  super( context, attrs, defStyle );
		   init();
		   init_2();
	  }

	 private void init() {
	    paint = new Paint();
	    paint.setAntiAlias(true);
	    paint.setStrokeWidth(4);
	    paint.setTextSize(25);
	    paint.setStyle(Paint.Style.STROKE);
	    paint.setColor(Color.RED);
	  }
	 private void init_2() {
		 paint_2 = new Paint();
		 paint_2.setAntiAlias(true);
		 paint_2.setStrokeWidth(2);
		 paint_2.setTextSize(20);
		 paint_2.setStyle(Paint.Style.STROKE);
		 paint_2.setColor(Color.BLUE);
	}

	  @Override
	  protected void onDraw(Canvas canvas) {
	    int xPoint = getMeasuredWidth() / 2;
	    int yPoint = getMeasuredHeight() / 4;
	    


	    float radius = (float) (200);

	    // 3.143 is a good approximation for the circle
	    canvas.drawLine(xPoint, yPoint,
	        (float) (xPoint+radius*Math.sin((double) (-position) / max * 3.143 - 3.143/2)),
	        (float) (yPoint+radius*Math.cos((double) (-position) / max * 3.143 - 3.143/2)), paint);


		    
	    canvas.drawText(String.valueOf(position), xPoint, yPoint, paint_2);
	  }
	  
	   
		  

	  public void updateData(double position,double max) {
	    this.position = position;
	    this.max = max;
	    invalidate();
	  }

	} 